<?php session_start(); ?>
<?php
include('../ketnoi.php');
include_once("fckeditor/fckeditor.php") ;
if (!$_SESSION['user']) header("location: index.php"); // nếu biến session['banguyen'] chưa có thì trở về trang đăng nhập, copy dòng này vào trang nào muốn bảo vệ bằng mật khẩu
?>
<style type="text/css">
<!--
.error, .notice, .success {padding:.8em;margin:auto; margin-bottom:.5em;border:2px solid #AAF;width:570px;text-align: center}
.error {background: #ECECFF;color: red;border-color:#AAF;}
-->
</style>
<style type="text/css">
.xem {
FONT-SIZE: 10pt; 
	COLOR: #000000;
	BORDER:0px;
	background-color:#FFFFFF;
}
</style>
<script type="text/javascript" src="scripts/joomla.js"></script>
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script src="ckeditor/_samples/sample.js" type="text/javascript"></script>
<div class="m">
 <?php 
    $shop=$dulieu;
	if($_GET['action']=='view' && $_GET['option']=='com_structure')
	{
		$sql1 = "SELECT * FROM `".$shop."`.`thoigian` order by TG_MA asc"; 
		$ketqua = mysql_query($sql1) or die ('khong tim thay du lieu');
		$tong=mysql_num_rows($ketqua);
		if($_POST['limit']==""){$sotrang = ceil($tong/20);}else{
		$sotrang = ceil($tong/$_POST['limit']);}
	    $dem = -1;
		
	if(isset($_POST['trang'])){
	 $trang = $_POST['trang'];
	}else{	
     if(isset($_POST['end'])){
	  $trang =$sotrang;
	 }else{
	  if(isset($_POST['start'])){
	   $trang =1;
	  }else{
	   $trang=1;
	  }
	 }	
	}
?>
<div id="menu">
	<div style="float: right;">
	<div class="icon1">
<a  class="toolbar" href="index.php"><img src="images/toolbar/icon-32-cancel.png" alt="Remove"><br><span>Cancel</span></a>
	</div>
	</div>

	
	<div style="float: right;">
	<div class="icon1">
<a class="toolbar" href="?option=com_structure&action=insert"><img src="images/toolbar/icon-32-new.png" alt="New"><br><span>New</span></a>
	</div>
	</div>
</div>

<div class="header" style="background: url(images/dashboard/icon-48-article.png) no-repeat scroll 0% 0% transparent; text-indent: 30px; line-height: 50px;">
  <h2 style="margin: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;Thời gian học khóa đào tạo nghiệp vụ</h2></div><br /><br />
<form name="adminForm" action="" method="post">
					
					<input name="option" value="com_structure" type="hidden">
					<input name="boxchecked" type="hidden">
					<input name="task" value="" type="hidden">
					<input name="func" value="" type="hidden">

<table class="adminlist" width="100%">
<tbody><tr><th width="3%" class="title">#</th>
<th width="4%" class="title"><input name="toggle" value="" onclick="checkAll(<?php if($_POST['limit']==""){echo '20';}else{echo $_POST['limit']; } ?>)" type="checkbox"></th>
<th class="title" width="19%"> 	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Mã thời gian</th>
<th class="title" width="29%"> &nbsp;Ngày học</th>  	 	 	 	 	
<th class="title" width="20%"> &nbsp;Giờ bắt đầu</th>
<th class="title" width="13%"> &nbsp;Giờ kết thúc</th>
<th width="6%" class="title"> &nbsp;Sửa </th>
<th class="title" width="6%"> &nbsp;Xóa</th>
</tr>
 <?php 
	$stt=0;
	$t=0;
   while($dongDL = mysql_fetch_array($ketqua))
	  { 
	  $dem++;
	    if($_POST['limit']==""){$s=20;}
		else{$s=$_POST['limit'];}
		if($dem >= ($trang-1)*$s && $dem <= ($trang*$s)-1)
		{
  ?>
  
<tr class="row<?php echo $t ?>">
<td align="center"><?php echo $dem+1 ?></td>
<td align="center"><input id="cb<?php echo $stt ?>" name="product_id[<?php echo $dongDL['TG_MA']?>]" value="<?php echo $dongDL['TG_MA']?>" onclick="isChecked(this.checked);" type="checkbox"></td>
<td><?php echo $dongDL['TG_MA']?>
 </td>
<td ><?php echo $dongDL['TG_NOTE']?></td>
<td ><?php echo $dongDL['TG_FROM']?></td>
<td><?php echo $dongDL['TG_TO']?></td>  	
<td align="center"><a href="?option=com_structure&action=update&amp;id=<?php echo $dongDL['TG_MA'] ?>"><img src="images/edit_f2.png" width="20" height="20" name="Edit<?php echo $stt+1 ?>" alt="Edit" border="0"></a></td>
<td align="center"><a class="toolbar" href="?option=com_structure&action=delete&amp;id=<?php echo $dongDL['TG_MA'] ?>" onclick="return confirm('Bạn có chắc chắn muốn xóa?');"><img src="images/delete_f2.png" width="20" height="20"alt="Delete" name="delete<?php echo $stt+1 ?>" align="middle" border="0"></a></td>
</tr>
	 <?php
	 $stt=$stt+1;
	 if($t==0)$t=1;
	 else $t=0;
	 }
	  }//ket thuc ham while in du lieu
	  ?>
</tbody></table>

<table class="adminlist"><tbody>
<?php if($sotrang > 1 && $keyword==""){?>
<tr>
  <td colspan="3" align="center"> 
  <input name="start" class="button2" type="submit" value="Start"/>
  <?php
for($i=1; $i<=$sotrang; $i++)
{ ?>
	<input name="trang" class="button" type="submit" value="<?php echo $i;?>"/>
<?php 
}
?>
<input name="end" class="button2" type="submit" value="End"/></td></tr>
<?php } ?>
<?php 
if($keyword=="" && $chude=='' && $trangthai==''){
?>
<tr><td width="48%" align="right" nowrap="nowrap">Display #</td><td>
<select class="inputbox" name="limit" size="1" onchange="this.form.submit();">
<option value="5"  <?php if($_POST['limit']==5) echo "selected='selected'" ?>>5</option>
<option value="10" <?php if($_POST['limit']==10) echo "selected='selected'" ?>>10</option>
<option value="15" <?php if($_POST['limit']==15) echo "selected='selected'" ?>>15</option>
<option value="20" <?php if($_POST['limit']=='') echo "selected='selected'" ?>>20</option>
<option value="25" <?php if($_POST['limit']==25) echo "selected='selected'" ?>>25</option>
<option value="30" <?php if($_POST['limit']==30) echo "selected='selected'" ?>>30</option>
<option value="50" <?php if($_POST['limit']==35) echo "selected='selected'" ?>>50</option>
</select>
</td><td width="48%" align="left" nowrap="nowrap">Results 1 - 
<?php if($_POST['limit']==''){if($tong < 20 ){echo $tong;}else echo '20';} else{if($_POST['limit'] > $tong ){echo $tong;}else echo $_POST['limit'];}?> of <?php echo $tong ?></td></tr>
<?php }else{
?>
<tr><td width="48%" align="right" nowrap="nowrap">Display #</td><td>
<select class="inputbox" name="limit" size="1" disabled="disabled">
<option><?php echo $tong1; ?></option>
</select>
</td><td width="48%" align="left" nowrap="nowrap"><?php if($tong1 >0){?>Results 1 - 
<?php echo $tong1;?> of <?php echo $tong1; }?></td></tr>
<?php
}
?>
</tbody></table>
</form>
<?php
}//ket thuc view

if($_GET['action']=='delete' && $_GET['option']=='com_structure')
	{
		  $sql = "Delete from `".$shop."`.`thoigian` where TG_MA = '".$_GET['id']."'";
		  $delete = mysql_query($sql);
          echo"<script language=javascript>window.location='index.php?option=com_structure&action=view';</script>";
	  }// ket thuc kiem tra action Delete
	  
 
if($_GET['action']=='insert' && $_GET['option']=='com_structure')
{
	
 if ( isset( $_POST['txtMa'] ) ){	
 	$error="";
	if($_POST['txtMa']  =='' || $_POST['txtFrom']=="" || $_POST['txtTo'] == '' || $_POST['txtNote'] == ''){ 
	  $error="Vui lòng nhập đầy đủ các field.";
    }else{
       $sql = "INSERT INTO `".$shop."`.`thoigian` (`TG_MA`,`TG_FROM`,`TG_TO`,`TG_NOTE`) VALUES ('".$_POST['txtMa']."', '".$_POST['txtFrom']."', '".$_POST['txtTo']."', '".$_POST['txtNote']."');";
       $insert = mysql_query($sql);
       echo"<script language=javascript>window.location='index.php?option=com_structure&action=view';</script>";
	}

}
	?>
	<div id="menu">
	<div style="float: right;">
	<div class="icon1">
<a  class="toolbar" href="?option=com_structure&action=view"><img src="images/toolbar/icon-32-cancel.png" alt="Remove"><br><span>Cancel</span></a>
	</div>
	</div>
	
	<div style="float: right;">
	<div class="icon1">
<a class="toolbar" onclick="adminForm2.submit();"><img src="images/toolbar/icon-32-save.png"  alt="New"><br><span>Save</span></a>
	</div>
	</div>
</div>

<div class="header" style="background: url(images/dashboard/icon-48-article-add.png) no-repeat scroll 0% 0% transparent; text-indent: 30px; line-height: 50px;">
  <h2 style="margin: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;Thời gian học khóa đào tạo nghiệp vụ: <small><small>[ Thêm mới ]</small></small></h2>
</div><br /><br />
<?php
	if($error!=""){
	?>
	 <div class="error" align="center"><img src='../images/cancel_f2.png' width='10px' height='10px'/> <?php echo $error ?></div>
  <?php
  }
?>
		<form name="adminForm2" action="" method="post" enctype="multipart/form-data">
<table style=" width:60%;" class="adminform">
	<tbody><tr> 
   		<td width="100%" valign="top">
			<table width="100%" border="0">
      			<tbody>                <tr> 
       				<td colspan="2" align="left"><span style="font-weight:bold; font-size:14px; color:#00F">Thông tin thời gian học</span></td>
    			</tr>
    			<tr class="row1"> 
      				<td width="26%"><div style="text-align: right; font-weight: bold;">Mã (1 kí tự):</div>      				</td>
      				<td width="74%"><input style="width:300px; margin-left:10px" name="txtMa" id="txtMa" type="text" value=""  tabindex="3"/> </td>
    			</tr>
               <tr class="row0"> 
      				<td width="26%"><div style="text-align: right; font-weight: bold;">Ngày học:</div>      				</td>
      				<td width="74%"><input style="width:300px; margin-left:10px" name="txtNote" id="txtNote" type="text" value=""  tabindex="4"/></td>
    			</tr>
                <tr class="row1"> 
      				<td width="26%"><div style="text-align: right; font-weight: bold;">Giờ bắt đầu:</div>      				</td>
      				<td width="74%"><input style="width:300px; margin-left:10px" name="txtFrom" id="txtFrom" type="text"  value=""  tabindex="3"/> </td>
    			</tr>
               <tr class="row0"> 
      				<td width="26%"><div style="text-align: right; font-weight: bold;">Giờ kết thúc:</div>      				</td>
      				<td width="74%"><input style="width:300px; margin-left:10px" name="txtTo" id="txtTo" type="text" value=""  tabindex="4"/></td>
    			</tr>
    			  <tr class="row0"> 
    					    
		      		<td valign="top" width="26%">&nbsp;</td>
		      		<td width="74%">&nbsp;</td>		    
    			  </tr>
		    </table>
 		</td>
  	</tr>
</tbody></table>
  </form>
<?php
}// ket thuc kiem tra action insert



if($_GET['action']=='update' && $_GET['option']=='com_structure')
	{
		$sql ="SELECT * from `".$shop."`.`thoigian` where TG_MA = '".$_GET['id']."'";
		$ketqua = mysql_query($sql);
		$dulieu = mysql_fetch_array($ketqua);
		
		
if ( isset( $_POST['txtMa'] ) ){	
 	$error="";
	if($_POST['txtMa']=="" || $_POST['txtFrom']=="" || $_POST['txtTo']=="" || $_POST['txtNote']==""){
	  $error="Vui lòng nhập đầy đủ các field.";
    }else{
       $sql = "UPDATE `".$shop."`.`thoigian` SET  `TG_MA` = '".$_POST['txtMa']."', `TG_FROM` = '".$_POST['txtFrom']."', `TG_TO` = '".$_POST['txtTo']."', `TG_NOTE` = '".$_POST['txtNote']."'  WHERE `thoigian`.`TG_MA` = '".$_GET['id']."'";
      $update = mysql_query($sql) or die($sql);
      echo"<script language=javascript>window.location='index.php?option=com_structure&action=view';</script>";   	 	 	 	
	}

}
	?>
<div id="menu">
	<div style="float: right;">
	<div class="icon1">
<a  class="toolbar" href="?option=com_structure&action=view"><img src="images/toolbar/icon-32-cancel.png" alt="Remove"><br><span>Cancel</span></a>
	</div>
	</div>
	
	<div style="float: right;">
	<div class="icon1">
<a class="toolbar" onclick="adminForm3.submit();"><img src="images/toolbar/icon-32-save.png"  alt="New"><br><span>Save</span></a>
	</div>
	</div>
</div>

<div class="header" style="background: url(images/dashboard/icon-48-article-add.png) no-repeat scroll 0% 0% transparent; text-indent: 30px; line-height: 50px;">
  <h2 style="margin: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;Thời gian học khóa đào tạo nghiệp vụ: <small><small>[ Sửa]</small></small></h2>
</div><br /><br />
		<form name="adminForm3" action="" method="post" enctype="multipart/form-data">
<table style=" width:60%;" class="adminform">
	<tbody><tr> 
   		<td width="100%" valign="top">
			<table width="100%" border="0">
      			<tbody>                <tr> 
       				<td colspan="2" align="left"><span style="font-weight:bold; font-size:14px; color:#00F">Thông tin thời gian học</span></td>
    			</tr>
    			<tr class="row1"> 
      				<td width="26%"><div style="text-align: right; font-weight: bold;">Mã (1 kí tự):</div>      				</td>
      				<td width="74%"><input style="width:300px; margin-left:10px" name="txtMa" id="txtMa" type="text" value="<?php echo $dulieu['TG_MA'] ?>"  tabindex="3"/> </td>
    			</tr>
               <tr class="row0"> 
      				<td width="26%"><div style="text-align: right; font-weight: bold;">Ngày học:</div>      				</td>
      				<td width="74%"><input style="width:300px; margin-left:10px" name="txtNote" id="txtNote" type="text" value="<?php echo $dulieu['TG_NOTE'] ?>"  tabindex="4"/></td>
    			</tr>
                <tr class="row1"> 
      				<td width="26%"><div style="text-align: right; font-weight: bold;">Giờ bắt đầu:</div>      				</td>
      				<td width="74%"><input style="width:300px; margin-left:10px" name="txtFrom" id="txtFrom" type="text"  value="<?php echo $dulieu['TG_FROM'] ?>"  tabindex="3"/> </td>
    			</tr>
               <tr class="row0"> 
      				<td width="26%"><div style="text-align: right; font-weight: bold;">Giờ kết thúc:</div>      				</td>
      				<td width="74%"><input style="width:300px; margin-left:10px" name="txtTo" id="txtTo" type="text" value="<?php echo $dulieu['TG_TO'] ?>"  tabindex="4"/></td>
    			</tr>
    			  <tr class="row0"> 
    					    
		      		<td valign="top" width="26%">&nbsp;</td>
		      		<td width="74%">&nbsp;</td>		    
    			  </tr>
		    </table>
 		</td>
  	</tr>
</tbody></table>
</form>
<?php
}//ket thuc update
?>


</div>
